///////////////////////////////////////////////////////
///产生随机验证码(输入任意位数，有数字和字母，字母大写，不重复)
/// idea: String.fromCharCode(num)
function securityCode(footage) {
    var charLib = [];     //字符库，动态生成
    for (var i = 0; i < 10; i++) {
        charLib.push(i);    // build 0-9
    }
    for (var i = 65; i <= 90; i++) {
        charLib.push(String.fromCharCode(i));   // build 'A'-'Z'
    }

    var buildIndexLib = [];     //索引库，以此向字符库取数据
    while (buildIndexLib.length < footage) {
        var randomNum = Math.floor(Math.random() * charLib.length);
        buildIndexLib.indexOf(randomNum) !== -1?randomNum:buildIndexLib.push(randomNum);    //去重
    }

    var buildCode = new String;     //验证码
    for (var i in buildIndexLib) {
        var buildChar = charLib[buildIndexLib[i]];  //取出字符
        buildCode += buildChar;     //合成验证码
    }
    return(buildCode);
}
console.log(securityCode(10))
